/**
 * Project Name:dsrs-systemservice-service
 * File Name:DatadicTypeServiceImpl.java
 * Package Name:com.bwda.dsrs.systemservice.service.impl;
 * Date:2019年4月28日
 * Copyright (c) 2019, 江苏保旺达软件有限公司 All Rights Reserved.
 */
package com.bwda.dsrs.systemservice.service.impl;

import com.bwda.dsrs.systemservice.domain.Constants;
import com.bwda.dsrs.systemservice.domain.exception.SystemServiceException;
import com.bwda.dsrs.systemservice.domain.po.datadictype.DatadicTypePo;
import com.bwda.dsrs.systemservice.domain.condition.datadictype.DatadicTypeCondition;
import com.bwda.dsrs.systemservice.mapper.DatadicTypeMapper;
import com.bwda.dsrs.systemservice.service.DatadicTypeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 数据字典类型
 *
 * @author liangjianyong
 * @date 2019/4/8
 */
@Service
public class DatadicTypeServiceImpl extends AbstractBaseServiceImpl<DatadicTypePo, DatadicTypeCondition, DatadicTypeMapper> implements DatadicTypeService {

    @Override
    public int queryCount(DatadicTypeCondition condition) {
        condition.setDelFlag(Constants.NOT_DELETED);
        return super.queryCount(condition);
    }

    @Override
    public List<DatadicTypePo> queryList(DatadicTypeCondition condition) {
        condition.setDelFlag(Constants.NOT_DELETED);
        return super.queryList(condition);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public void insert(DatadicTypePo po) {
        po.setDelFlag(Constants.NOT_DELETED);
        //新增时默认排序字段+1
        po.setOrderNum(selectMaxOrderNum()+1);
        super.insert(po);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public int update(DatadicTypePo po) {
        po.setDelFlag(Constants.NOT_DELETED);
        return super.update(po);
    }


    @Override
    @Transactional(rollbackFor = {Exception.class})
    public void updateWithValid(DatadicTypePo po)
        throws SystemServiceException {
        po.setDelFlag(Constants.NOT_DELETED);
        super.updateWithValid(po);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public void delete(Object id) throws SystemServiceException {
        DatadicTypePo po=new DatadicTypePo();
        po.setId((Integer) id);
        po.setDelFlag(Constants.DELETED);
        this.getMapper().update(po);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public void batchDelete(List<Integer> datadicTypeIdList) {
        DatadicTypePo po=new DatadicTypePo();
        po.setIdList(datadicTypeIdList);
        po.setDelFlag(Constants.DELETED);
        this.getMapper().update(po);
    }

    @Override
    public Integer selectMaxOrderNum() {
        return this.getMapper().selectMaxOrderNum();
    }

    @Override
    public int countByCodeorName(DatadicTypeCondition condition) {
        return this.getMapper().countByCodeorName(condition);
    }


}